﻿using System.Data;
using Util.Common;

namespace Tms.BLL
{
    public partial class manager
    {
        private readonly DAL.manager dal = new DAL.manager();
                
        //是否存在
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        //是否存在
        public bool Exists(string user_name)
        {
            return dal.Exists(user_name);
        }

        //获取Salt
        public string GetSalt(string user_name)
        {
            return dal.GetSalt(user_name);
        }

        //增加一条数据
        public int Add(Model.manager model)
        {
            return dal.Add(model);
        }

        //更新一条数据
        public bool Update(Model.manager model)
        {
            return dal.Update(model);
        }

        //删除一条数据
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        //获取一个实体对象
        public Model.manager GetModel(int id)
        {
            return dal.GetModel(id);
        }

        //获取一个实体对象
        public Model.manager GetModel(string user_name, string password)
        {
            return dal.GetModel(user_name, password);
        }

        //获取一个实体对象
        public Model.manager GetModel(string user_name, string password, bool is_encrypt)
        {
            //检查一下是否需要加密
            if (is_encrypt)
            {
                //先取得该用户的随机密钥
                string salt = dal.GetSalt(user_name);
                if (string.IsNullOrEmpty(salt))
                {
                    return null;
                }
                //把明文进行加密重新赋值
                password = DESEncrypt.Encrypt(password, salt);
            }
            return dal.GetModel(user_name, password);
        }

        //获取前几行数据
        public DataSet GetList(int Top, string strWhere, string strOrder)
        {
            return dal.GetList(Top, strWhere, strOrder);
        }

        //获取查询分页数据
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string strOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, strWhere, strOrder, out recordCount);
        }

    }
}